package com.htudata.item.controller;

import com.alibaba.fastjson.JSONObject;
import com.htudata.common.enums.RequestSeqEnum;
import com.htudata.common.enums.RequestStatusEnum;
import com.htudata.common.vo.ResponseResult;
import com.htudata.core.util.ResultGenerator;
import com.htudata.item.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class ItemController {

  @Autowired
  private ItemShowService itemShowService;
  
  @Autowired
  private ItemShowServiceV2 itemShowServiceV2;
  
  @Autowired
  private ItemSelectService itemSelectService;
  
  @Autowired
  private ItemSelectServiceV2 itemSelectServiceV2;
  
  @Autowired
  private ItemSelectService2V2 itemSelectService2V2;
  
  @Autowired
  private ItemSelectService2 itemSelectService2;
  
  @Autowired
  private ItemCUDService itemCUDService;
  
  @Autowired
  private ItemServiceDemo itemServiceDemo;
  
  @RequestMapping(value = {"/v1/live/nodes/{nodeId}/items"}, method = {RequestMethod.PUT})
  @ResponseBody
  public ResponseResult showOrHideItems(@PathVariable(required = true) String nodeId, @RequestParam(required = true) int isShowed, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_001.getCode(), this.itemCUDService
          .showOrHideItems(nodeId, isShowed, a2));
    } catch (Exception e) {
      log.error("showOrHideItems",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_001.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/items"}, method = {RequestMethod.POST})
  @ResponseBody
  public ResponseResult postItems(@RequestBody(required = true) JSONObject params, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_001.getCode(), this.itemCUDService
          .postItems(params, a2));
    } catch (Exception e) {
      log.error("postItems",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_001.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/items"}, method = {RequestMethod.GET})
  @ResponseBody
  public ResponseResult getItems(@RequestParam(required = false, defaultValue = "-1") String flowId, @RequestParam(required = false, defaultValue = "-1") String nodeId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_001.getCode(), this.itemSelectService
          .getItems(flowId, nodeId, a2));
    } catch (Exception e) {
      log.error("getItems",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_001.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v2/live/items"}, method = {RequestMethod.GET})
  @ResponseBody
  public ResponseResult getItems2(@RequestParam(required = false, defaultValue = "-1") String flowId, @RequestParam(required = false, defaultValue = "-1") String nodeId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_001.getCode(), this.itemSelectServiceV2
          .getItems(flowId, nodeId, a2));
    } catch (Exception e) {
      log.error("getItems2",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_001.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/nodes/{nodeId}/items"}, method = {RequestMethod.GET})
  @ResponseBody
  public ResponseResult getItemsOfNode(@PathVariable(required = true) String nodeId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_001.getCode(), this.itemSelectService2
          .getItemsByNodeId(nodeId, a2));
    } catch (Exception e) {
      log.error("getItemsOfNode",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_001.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v2/live/nodes/{nodeId}/items"}, method = {RequestMethod.GET})
  @ResponseBody
  public ResponseResult getItemsOfNode2(@PathVariable(required = true) String nodeId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_000.getCode(), this.itemSelectService2V2
          .getItemsByNodeId(nodeId, a2));
    } catch (Exception e) {
      log.error("getItemsOfNode2",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_000.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/itemData"}, method = {RequestMethod.GET})
  @ResponseBody
  public ResponseResult getItemData(@RequestParam(required = false, defaultValue = "-1") String flowId, @RequestParam(required = false, defaultValue = "-1") String nodeId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_001.getCode(), this.itemShowService
          .getItemData(flowId, nodeId, a2));
    } catch (Exception e) {
      log.error("getItemData",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_001.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v2/live/itemData"}, method = {RequestMethod.GET})
  @ResponseBody
  public ResponseResult getItemData2(@RequestParam(required = false, defaultValue = "-1") String flowId, @RequestParam(required = false, defaultValue = "-1") String nodeId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_001.getCode(), this.itemShowServiceV2
          .getItemData(flowId, nodeId, a2));
    } catch (Exception e) {
      log.error("getItemData2",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_001.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
}
